pc.script.create('GameStateManager', function (app) {
    // Creates a new GameStateManager instance
    var GameStateManager = function (entity) {
        this.entity = entity;
    };

    GameStateManager.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () 
        {
            //needInit
            this.start = false;
            this.startgame = false;
            this.lose = false;
            var player = app.root.findByName("player");
            this.playercontrol = player.script.PlayerControl;
            this.playtimer = 0;
            initHandle();
        },

        // Called every frame, dt is time in seconds since last update
        update: function (dt) 
        {
            if(!this.start || !this.startgame)
            {
                return;
            }
            
            if(this.lose)
            {
                return;
            }
            
            this.playtimer += dt;

        },
        
        
        GameStartGame:function()
        {
            gameAction.gameStart();
        },

        GameStart:function()
        {

            gameAction.start();
            
        },
        
        GameEnd:function()
        {

            var scoreinfo = {"score":this.playercontrol.score,"coin":this.playercontrol.coins};
            
            var scores = encryptscore(JSON.stringify(scoreinfo),window.token).toString()
            scoreinfo.scores = scores;
            gameAction.gameEnd(scoreinfo);
        },
        
        
        
        
        Init:function()
        {
            gameAction.gameInit();
           
            this.playtimer = 0;
            this.startgame = false;
            this.lose = false;
        }
        
    };

    return GameStateManager;
});